const fp = require('lodash/fp')
const { Maybe, Container } = require('./support')

// 练习一
let a = fp.add(1, 2)
let maybe = Maybe.of( [5, 6,1])
let ex1 = n => maybe.map(arr => fp.map(v => fp.add(v, n), arr))._value
console.log(ex1(1))



// 练习二
let xs = Container.of( [ 'do' , 'ray ','me ', 'fa ', 'so', 'la ', 'ti', 'do' ] )
let ex2 = fn => xs.map(fn)._value
console.log(ex2(fp.first))



//练习三
let safeProp = fp.curry ( function ( x,o){
  return Maybe.of(o[x])
})
let user = { id: 2, name :'Albert' }
let ex3 = () => {
  return safeProp("name", user).map(item => fp.first(item))._value
}
console.log(ex3(user))




//练习四
let ex4 = function (n) {
  return Maybe.of(n).map(parseInt)._value
}
console.log(ex4(2))
